package work.soho.proxy.component.impl;

import work.soho.proxy.aliyun.parts.DdnsLanPart;
import work.soho.proxy.aliyun.parts.DdnsWanPart;
import work.soho.proxy.aliyun.parts.PartsManage;
import work.soho.proxy.component.IComponent;

import java.util.ArrayList;

/**
 * ddns服务空间
 */
public class DomainImpl implements IComponent {
    /**
     * 启动ddns
     *
     * @return
     */
    @Override
    public boolean start() {
        try {
            ArrayList<String> list = new ArrayList<>();
            list.add(DdnsLanPart.class.getName());
            list.add(DdnsWanPart.class.getName());
            PartsManage.check(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean stop() {
        return false;
    }

    @Override
    public boolean unRegister() {
        return false;
    }

    /**
     * 获取远程ddns ip地址
     *
     * @return
     */
    public static String getDdnsLanIp() {
        return ((DdnsLanPart) PartsManage.getPartByName(DdnsLanPart.class.getName())).getDnsLanRecode().getValue();
    }

    /**
     * 获取广域网IP地址
     *
     * @return
     */
    public static String getDdnsWanIp() {
        return ((DdnsWanPart)PartsManage.getPartByName(DdnsWanPart.class.getName())).getDnsLanRecode().getValue();
    }
}
